package com.cgsrp.cgsrp_user_province.service.impl;

import com.cgsrp.cgsrp_user_province.dao.ProvincesMapper;
import com.cgsrp.cgsrp_user_province.domain.Provinces;
import com.cgsrp.utils.Result;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.cgsrp.cgsrp_user_province.dao.UserAddressMapper;
import com.cgsrp.cgsrp_user_province.domain.UserAddress;
import com.cgsrp.cgsrp_user_province.service.UserAddressService;

import java.util.List;

@Service
public class UserAddressServiceImpl implements UserAddressService{

    @Resource
    private UserAddressMapper userAddressMapper;

    @Resource
    private ProvincesMapper provincesMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return userAddressMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(UserAddress record) {
        return userAddressMapper.insert(record);
    }

    @Override
    public int insertSelective(UserAddress record) {
        return userAddressMapper.insertSelective(record);
    }

    @Override
    public UserAddress selectByPrimaryKey(Integer id) {
        return userAddressMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(UserAddress record) {
        return userAddressMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(UserAddress record) {
        return userAddressMapper.updateByPrimaryKey(record);
    }

    @Override
    public Result list(Integer userId) {
        List<UserAddress> addresses = userAddressMapper.findByUserId(userId);
        for (UserAddress address : addresses) {
            Provinces provice = provincesMapper.findById(address.getProvinceId());
            address.setMergerName(provice.getMergername());
        }
        return Result.suc("成功",addresses);
    }

}
